$(() => {
    let $btn1 = $("#btn1");
    let $btn2 = $("#btn2");
    let $btn3 = $("#btn3");
    let $btn4 = $("#btn4");
    let $username = $("#username");
    let $password = $("#password");
    let $confirm = $("#confirm");
    let $email = $("#email");
    let $code = $("#code");
    let data_code;
    $btn1.click(()=>{
        location.href="{LINK_login}";
    });
    $btn2.click(()=>{
        location.href="{LINK_forget}";
    });
    $btn3.click(()=>{
        $("#main").addClass("el-loading");
        let email = $email.val();
        $.post("{LINK_register/sendMail}",{
            email:email
        },text=>{
            $("#main").removeClass("el-loading");
            let data=JSON.parse(text);
            if(data.status){
                data_code=data.code;
                dialog("提示","邮件发送成功，请查看您的邮箱。");
            }else{
                dialog("错误","邮件发送失败，请联系管理员。");
            }
        });
    });
    $btn4.click(()=>{
        $("#main").addClass("el-loading");
        let username = $username.val();
        let password = $password.val();
        let confirm_pwd = $confirm.val();
        let email = $email.val();
        let code = $code.val();
        if(username.length>=3&&username.length<=15){
            if(password==confirm_pwd){
                if(password.length>=6&&password.length<=25){
                    if(data_code){
                        if(data_code==code){
                            $.post("#",{
                                username:username,
                                password:password,
                                email:email
                            },text=>{
                                $("#main").removeClass("el-loading");
                                let data=JSON.parse(text);
                                if(data.status){
                                    dialog("提示",data.msg);
                                }else{
                                    dialog("错误","登录失败："+data.msg);
                                }
                            });
                        }else{
                            $("#main").removeClass("el-loading");
                            dialog("错误","邮箱验证码不正确，请检查后重试。");
                        }
                    }else{
                        $("#main").removeClass("el-loading");
                        dialog("错误","您还没有验证邮箱，请发送邮件进行验证。");
                    }
                }else{
                    $("#main").removeClass("el-loading");
                    dialog("错误","密码必须为6-25个字符");
                }
            }else{
                $("#main").removeClass("el-loading");
                dialog("错误","两次密码不一致，请重新输入");
            }
        }else{
            $("#main").removeClass("el-loading");
            dialog("错误","用户名必须为3-12个字符");
        }
    });
})